#pragma once
#include <map>
#include <list>
#include "msg.h"
#include <string>
namespace acl
{
namespace mqtt
{
class msg_storer
{
public:
	static msg_storer &get_instance() 
	{
		static msg_storer inst;
		return inst;
	}
	void store_msg(const publish_msg &msg) 
	{
		if(msg.fixed_header_.RETAIN_ && !msg.payload_) {
			auto it = msgs_.find(msg.topic_name_);
			if(it != msgs_.end())
				msgs_.erase(it);
			return;
		}

		msgs_[msg.topic_name_].push_back(msg);
	}
	const std::list<publish_msg> &get_msgs(const std::string &topic) 
	{
		return msgs_[topic];
	}
private:
	std::map<std::string, std::list<publish_msg>> msgs_;
};
}
}